#pragma once
#ifdef _DEBUG  
#pragma comment(lib,"opencv_world342d.lib") 
#else
#pragma comment(lib,"opencv_world342.lib") 
#endif
# include "headfile.h"

void PreProcess(const cv::Mat& image, cv::Mat& image_blob);
cv::Mat forwd(torch::jit::script::Module module, cv::Mat inpimg, int scale);
void MatToCImage(cv::Mat& mat, CImage& cimage);
cv::Mat Rot(cv::Mat inpimg, int ang);

class DETECTor
{
public:
	cv::Mat NNForwardGL(cv::Mat inp);
	cv::Mat NNForwardGB(cv::Mat inp);
	cv::Mat getMImage();

	void Init(
		cv::String model_path_GL,
		cv::String model_path_GB,
		int scale,
		bool isCamera,
		int cameraID
	);
	void detectGL();
	void detectGB();
	void reprocess();
	void end();
	void dMatToCImage(cv::Mat& mat, CImage& cimage);

	bool getFrame();
	bool openCapture(cv::String video_path = "", int port = 0);
	bool show();

	CImage getCImage();
	
public:
	cv::Mat ooimg[100];
	cv::Mat image;
	cv::Mat image_gray;
	CImage cimage;

	torch::jit::script::Module module_GL;
	torch::jit::script::Module module_GB;

	std::vector<int> w_GL, h_GL;
	std::vector<int> w_GB, h_GB;
	std::vector<int> x1_GL, y1_GL;
	std::vector<int> x1_GB, y1_GB;
	std::vector<float> area_first;
	std::vector<float> xx_Ratio, yy_Ratio;
	std::vector<float> xx_Delta, yy_Delta;
	std::vector<float> xx;

	std::vector<std::vector<cv::Point>> cc_GL;
	std::vector<std::vector<cv::Point>> cc_GB;

	cv::VideoCapture capture;

	int reX;
	int reY;

	int saveCount = 5;
	int GB_start = 5;
	int valid_count_GL = 0;
	int valid_count_GB = 0;
	int x1_GL_Mean, y1_GL_Mean;
	int xm_GL_Mean, ym_GL_Mean;
	int w_GL_Mean, h_GL_Mean;
	int x1_GB_Mean, y1_GB_Mean;
	int xm_GB_Mean, ym_GB_Mean;
	int w_GB_Mean, h_GB_Mean;
	int xx1_Mean, yy1_Mean;
	int xx2_Mean, yy2_Mean;
	int scale;

	int cameraID;
	int mode = 1;

	int N_threshold = 42;

	long frame_count = 0;

	bool isGBValid = false;
	bool isShow = false;
	bool isCamera = false;
	bool isOpen = false;

	float  xx_Delta_Mean, yy_Delta_Mean;
};
